﻿@using E5_KhuyenMaiVang.Models
@model IEnumerable<E5_KhuyenMaiVang.Models.DEAL>
@{
    ViewBag.Title = "TKM_QuanLy";
    Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
    var DealStatuses = ViewBag.DealStatuses;
    int i = 0;
}
@section menu
{
    <h3>
        Admin</h3>
    <ul class="nav">
        <li><a href="@Url.Action("TKM_QuanLy", "Admin")" style="text-decoration:underline; font-weight:bold;">
            Quản lý khuyến mãi</a></li>
        <li><a href="@Url.Action("TKM_Them", "Admin")">Thêm khuyến mãi</a></li>
    </ul>
}
<div class="top-bar">
    <a href="#" class="button">ADD NEW </a>
    <h1>
        QUẢN LÝ KHUYẾN MÃI</h1>
    <div class="breadcrumbs">
        Tin khuyến mãi/ <a href="#">Quản lý khuyến mãi</a></div>
</div>
<form method="post" action="@Url.Action("SearchDeal", "Admin")">
<div class="select-bar">
    <label>
        <select name="Status">
            <option value="0">Tất cả</option>
            @foreach (var item in DealStatuses)
            {
                <option value="@item.StatusID">@item.StatusName</option>
            }
        </select>
    </label>
    <input type="text" name="DealName" />
    <label>
        <input type="submit" name="Submit" value="Search" />
    </label>
</div>
</form>
@if (ViewBag.Error != null) { 
                    <div class="ui-widget">
			<div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
				<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
				<strong>Alert:</strong> @ViewBag.Error</p>
			</div>
		</div>
                }
                @if (ViewBag.Success != null) { 
                <div class="ui-widget">
			<div class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;">
				<p><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
				<strong>Successful!</strong> @ViewBag.Success</p>
			</div>
		</div>
                }
<div class="table">
    <table class="listing" cellpadding="0" cellspacing="0">
        <tr>
            <th>
                Số thứ tự
            </th>
            <th>
                Doanh nghiệp
            </th>
            <th>
                Tên khuyến mãi
            </th>
            <th>
                Ngày đăng
            </th>
            <th>
                Ngày hết hạn
            </th>
            <th>
                Tình trạng
            </th>
            <th>
                Cập nhật
            </th>
            <th>
                Xóa
            </th>
        </tr>
        @foreach (var item in Model)
        {
            <tr>
                <td class="style1">
                    @(++i)
                </td>
                <td>
                @if (item.COMPANY != null)
                {
                    @item.COMPANY.CompanyName
                }
                </td>
                <td>
                    @item.DealName
                </td>
                <td>
                    @string.Format("{0:dd/MM/yyyy}", item.StartDate)
                </td>
                <td>
                    @string.Format("{0:dd/MM/yyyy}", item.EndDate)
                </td>
                <form method="post" action="@Url.Action("UpdateDealStatus", "Admin", new { DealID = item.DealID })">
                <td>
                    <select name="Status" onchange="this.form.submit()">
                        @foreach (var sitem in DealStatuses)
                        {
                            if (item.StatusID == sitem.StatusID)
                            {
                            <option value="@sitem.StatusID" selected="true">@sitem.StatusName</option>
                            }
                            else
                            {
                            <option value="@sitem.StatusID">@sitem.StatusName</option>
                            }
                        }
                    </select>
                </td>
                </form>
                <td>
                    <a href="@Url.Action("TKM_CapNhat", "Admin", new { dealID = @item.DealID })">
                        <img src="../Images/edit-icon.gif" width="16" height="16" alt="" /></a>
                </td>
                <td>
                    <a href="@Url.Action("TKM_Xoa", "Admin", new { dealID = @item.DealID})">
                        <img src="../Images/hr.gif" width="16" height="16" alt="" /></a>
                </td>
            </tr>
        }
    </table>
</div>
